<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2014/10/9
 * Time: 10:51
 * 问题选项表（多选，单选）
 */
class QuestionOption extends CActiveRecord
{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'question_option';
    }
    /**
     * 得到某个问题某个题目的选项
     */
    public function getBySubject($question_id,$subject_id)
    {
        $data = $this->findAll('question_id='.$question_id.' and subject_id='.$subject_id);
        if ($data) {
            $result = array();
            foreach ($data as $key => $val) {
                $result[$val['option_id']] = $val['content'];
            }
            return $result;
        }
        return $data;
    }
    /**
     * 
     * @param type $question_id
     * @return type
     * 根据问题得到选项
     */
    public function getByQuestion($question_id)
    {
        $data = $this->findAll('question_id='.$question_id);
        if ($data) {
            $result = array();
            foreach ($data as $key => $val) {
                $subject_id = $val['subject_id'];
                $content = json_decode($val['content'], true);
                if ($content) {
                    $result[$subject_id] = $content;
                }
            }
            return $result;
        }
        return $data;
    }
}